|
|
|
|
|
|
|
This section contains formulas for calculating the distances between various objects. Module Distance.bas contains functions that return these distances. Example program Distance demonstrates these functions. |
|
|
|
|
|
|
|
|
The distance between points A = (ax, ay, az) and B = (bx, by, bz) is written |AB|. This is the same as the length of the vector from A to B and is given by: |
|
|
|
 |
|
|
|
|
|<bx - ax, by - ay, bz - az>| =
Sqr((bx - ax)2 + (by - ay)2 + (bz - az)2) |
|
|
|
|
|
|
|
|
Suppose a line passes through point C = (cx, cy, cz) in the direction of the vector V = <vx, vy, vz>. Now consider a point P = (px, py, pz) as shown in Figure 19.6. |
|
|
|
|
|
|
|
|
A is the vector from point C to point P. A' is the projection of vector A along vector P. The section Projection of a Vector onto a Vector earlier in this chapter showed that: |
|
|
|
 |
|
|
|
|
|A'| = (A V)/|V| |
|
|
|
|
|
|
|
|
The shortest distance from point P to the line is along the vector A A' perpendicular to the line. That means the shortest distance from P to the line is |A A'|. |
|
|
|
|
|
|
|
|
Then the Pythagorean theorem says: |
|
|
|
 |
|
|
|
|
|A - A'| = Sqr(|A|2 - |A'|2)
= Sqr(|A|2 - ((A V)/|V|)2 |
|
|
|
|
|
|
|
|
Figure 19.6
The shortest distance from point P
to a line is along the vector A A'. |
|
|
|
|
|